package com.ozo.boot.common.log.event;

import cn.hutool.core.bean.BeanUtil;
import com.ozo.boot.system.entity.SysOperationLog;
import com.ozo.boot.system.pojo.dto.SysOperationLogDTO;
import com.ozo.boot.system.service.ISysOperationLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
 * 登录事件监听
 *
 * @author qiangesoft
 * @since 2024-07-11
 */
@Slf4j
@RequiredArgsConstructor
public class OperateLogListener {

    private final ISysOperationLogService sysOperationLogService;

    @Async
    @EventListener({OperationLogEvent.class})
    public void saveSysLog(OperationLogEvent event) {
        SysOperationLogDTO sysOperationLogDTO = (SysOperationLogDTO) event.getSource();
        SysOperationLog sysOperationLog = BeanUtil.copyProperties(sysOperationLogDTO, SysOperationLog.class);
        sysOperationLogService.save(sysOperationLog);
    }

}
